package myservice.android.activities;
 
import myservice.android.Global;
import myservice.android.R;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
 
public class ReportsActivity extends TabActivity {
	
	private TabHost mTabHost;	
	private TextView windowTitle;	
	private int selectedMonth, selectedYear;	

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.tab_host);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
        
    	Bundle extras = getIntent().getExtras();
    	if (extras != null) {
    		selectedMonth = extras.getInt("month");
    		selectedYear = extras.getInt("year");
    	}         
        
        windowTitle = (TextView) findViewById(R.id.titleText);               
 
		setupTabHost();
		mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

		setupTab(new TextView(this), Global.res.getString(R.string.tab_month)); 
		setupTab(new TextView(this), Global.res.getString(R.string.tab_year));	
		setupTab(new TextView(this), Global.res.getString(R.string.tab_graphs));
    	
    	windowTitle.setText(Global.res.getString(R.string.title_reports));		
		
	}
    
	private void setupTabHost() {
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup();
	}    

	private void setupTab(final View view, final String tag) {
		View tabview = createTabView(mTabHost.getContext(), tag);
		
		Intent intent;
		if (tag.equals(Global.res.getString(R.string.tab_month))) {
			intent = new Intent().setClass(this, ReportsMonthActivity.class);
			intent.putExtra("month", selectedMonth);
			intent.putExtra("year", selectedYear);			
		}
		else
		if (tag.equals(Global.res.getString(R.string.tab_year))) 
			intent = new Intent().setClass(this, ReportsYearActivity.class);
		else
			intent = new Intent().setClass(this, ReportsGraphsActivity.class);

		TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
		mTabHost.addTab(setContent);

	}

	private static View createTabView(final Context context, final String text) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
		TextView tv = (TextView) view.findViewById(R.id.tabsText);
		tv.setText(text);
		return view;
	}
                       
}